package com.yzr.util.converter;

import cn.hutool.core.io.FileUtil;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @description
 * @author: yzr
 * @date: 2021/10/29 17:42
 **/
@Component
public class ImageConversion implements Conversion {

    @Override
    public String convert(String filePath, String target) throws FileNotFoundException {
        // 获取文件名
        if (!FileUtil.isFile(filePath)) throw new FileNotFoundException("文件不存在");

        // 压缩图片
        try {
            Thumbnails.of(filePath).scale(0.5).toFile(target);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return target;
    }

    @Override
    public boolean convert(InputStream in, OutputStream out) {
        if (null == in) {
            throw new RuntimeException("读取流不能为空");
        }




        return false;
    }
}
